/*
 * @Description:
 * @Author: 胡涛
 * @Date: 2024-07-29 22:12:47
 * @LastEditors: 胡涛
 * @LastEditTime: 2024-07-30 00:08:34
 */

import { App } from "vue";

import * as echarts from "echarts/core";
import {
  BarChart,
  LineChart,
  PieChart,
  MapChart,
  GaugeChart,
  TreeChart,
  RadarChart,
  GraphChart,
  ScatterChart,
  HeatmapChart,
} from "echarts/charts";

import {
  LegendComponent,
  TitleComponent,
  TooltipComponent,
  GridComponent,
  // 数据集组件
  DatasetComponent,
  // 内置数据转换器组件 (filter, sort)
  TransformComponent,
  TimelineComponent,
  DataZoomSliderComponent,
  MarkLineComponent,
  MarkAreaComponent,
  MarkPointComponent,
} from "echarts/components";
import { LabelLayout, UniversalTransition } from "echarts/features";
import { CanvasRenderer } from "echarts/renderers";
import api from "@/api";

const themeNames = ["default"];

export default {
  install(app: App) {
    /**
     * 注册必须的组件
     */
    echarts.use([
      LegendComponent,
      TitleComponent,
      TooltipComponent,
      GridComponent,
      DatasetComponent,
      TransformComponent,
      TimelineComponent,
      DataZoomSliderComponent,
      MarkLineComponent,
      MarkAreaComponent,
      MarkPointComponent,
      BarChart,
      LineChart,
      PieChart,
      MapChart,
      GaugeChart,
      TreeChart,
      RadarChart,
      GraphChart,
      ScatterChart,
      HeatmapChart,
      LabelLayout,
      UniversalTransition,
      CanvasRenderer,
    ]);

    /**
     * 注册主题配置
     */
    themeNames.map((theme) => {
      api.get(`./echarts/${theme}.json`).then((res) => {
        console.log("theme content", res);
        echarts.registerTheme("vintage", res);
      });
    });
  },
};
